[696a78]: / Supporting Functions / Burst_supression.m

Download this file

88 lines (77 with data), 2.0 kB

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
function [ bur, sup ] = Burst_supression( x, Fs )
%UNTITLED2 Summary of this function goes here
% Detailed explanation goes here
supression_threshold = 10;%10;
% DETECT EMG ARTIFACTS.
% [be ae] = butter(6, [30 49]./(Fs/2)); % bandpass filter
% demg=filtfilt(be,ae,x);
% i0=1; i1=1; ct=0; dn=0;
% Nt = size(x,2);
% chunkSize = 5; % 5 second chunks
% a = zeros(1,Nt);
% while ~dn
% %% get next data chunk
% i0=i1;
% if i1 == Nt
% dn=1;
% end
%
% i1=i0+round(Fs*chunkSize);
% i1=min(i1,Nt);
% i01=i0:i1;
% ct=ct+1; % get next data chunk
%
% A(ct)=0; % set to 1 if artifact is detected
% de=demg(:,i01);
%
% %% check for emg artifact
% v=std(de);
% if v > 5
% A(ct)=1;
% end
% a(i01)=A(ct);
% end
% [c,l]=wavedec(x,9,'db2');
% A9=wrcoef('a',c,l,'db2',9);
%
% [c,l]=wavedec(x,10,'db2');
% A10=wrcoef('a',c,l,'db2',10);
%
% [c,l]=wavedec(x,11,'db2');
% A11=wrcoef('a',c,l,'db2',11);
%
% x_tmp = x - A9;
% CALCULATE ENVELOPE
x = smooth(x,10);
ME = abs(hilbert(x));
% ME = smooth(e,Fs/4); % apply 1/2 second smoothing
% e = ME;
ME_temp = sort(ME);
baseline = mean(ME_temp(1:Fs*1.5));
ME = ME-baseline;
% DETECT SUPRESSIONS
% apply threshold -- 10uv
z = (ME<supression_threshold);
% remove too-short suppression segments
z = fcnRemoveShortEvents(z,Fs/4);
% remove too-short burst segments
b = fcnRemoveShortEvents(1-z,Fs/4);
z = 1-b;
z = z';
%% RUN 'BS' ALGORITHM
went_low = find((z(1:end-1) == 0) & (z(2:end) == 1));
went_high = find((z(1:end-1) == 1) & (z(2:end) == 0));
if ~isempty(went_low)&&~isempty(went_high)
starting = went_high(1) < went_low(1);
if(starting == 0)
bur = [[1, went_high(1:length(went_low)-1)]; went_low]';
sup = [went_low(1:length(went_high)); went_high]';
end
if(starting == 1)
sup = [[1, went_low(1:length(went_high)-1)]; went_high]';
bur = [went_high(1:length(went_low)); went_low]';
end
else
bur = [];
sup = [];
end